package cn.house.dao;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;

import cn.house.entity.House;
import util.HibernateUtil;

public class HouseDaoImpl implements HouseDao {

	@Override
	public List<House> selectHouseByUserId(Integer userId) {
		return HibernateUtil.currentSession().
				createQuery("from House where user.id = ?")
				.setParameter(0, userId)
				.list();
	}

	@Override
	public List<House> selectAllHouse(String title) {
		//参数列表
		List<Object> parmsList = new ArrayList<Object>();
		String hql = "from House where 1=1 ";
		if(title!=null&&!title.equals("")){
			hql += " and title like ? ";
			parmsList.add(title);
		}
		
		Query query = HibernateUtil.currentSession().createQuery(hql);
		for (int i = 0; i < parmsList.size(); i++) {
			query.setParameter(i, parmsList.get(i));
		}
		return query.list();
	}
}
